﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leo.BL;
using Leo.Entities;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace VeterinariaDrLeo.Controllers
{
    public class LoteController : Controller
    {
        //
        // GET: /Lote/

        [Dependency]
        public ILoteBL loteBl { get; set; }

        public ActionResult Index()
        {
            var lote = loteBl.GetAllFromLote();
            return View(lote);
        }

        [HttpPost]
        public ActionResult Index(string criterio = "")
        {
            var lote = loteBl.GetFromLoteByCriterio(criterio);
            return View(lote);
        }

        public ActionResult Create()
        {
            var lote = loteBl.GetFromLoteByCriterio("");
            return View(lote);
        }

        [HttpPost]
        public ActionResult Create(Lote lote)
        {
                loteBl.AddLote(lote);
                return RedirectToAction("index");
            

        }

        public ActionResult Edit(Int32 id)
        {
            var lote = loteBl.GetFromLoteById(id);
            return View(lote);
        }
        [HttpPost]
        public ActionResult Edit(int id, Lote lote)
        {
               loteBl.UpdateLote(lote);
                return RedirectToAction("index");
            

        }

        public ActionResult Delete(Int32 id)
        {
            loteBl.RemoveLote(id);
            return View("index");

        }

      
    }
}
